<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>党建网</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../../assets/css/amazeui.css"/>
  <link rel="stylesheet" href="../../assets/css/admin.css">
  <link rel="stylesheet" href="../../css/pagination.css">

</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar amt-header">
</header>

<div class="am-cf">
  <!-- sidebar start -->
   <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
  </div>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content" >
       <div class="am-cf am-padding" style="margin-left:2%">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg" style="color:#BD2D30">子栏目</strong></div>
                </div>
                <div class="am-g" style="display:block" id="addBtn">
                    <div class="am-u-sm-6 " style="margin-left:2%">主栏目：
                                <select data-am-selected id="mcol">
                                </select>
                                <button type="button" class="am-btn am-btn-primary am-btn-xs" id="add_btn" style="margin-left:5%">添加子栏目</button>
                            </div>
	</div><br />
    
    <div class="am-g" id="proTab" style="display:block;height:600px">
      <div class="am-u-sm-8 " style="margin-left:2%">
        <form >
         <table class="am-table am-table-bordered">
            <thead>
              <tr style="font-size:15px">
                <th>栏 目 名 称</th><th>添 加 时 间</th><th>操作</th>
              </tr>
          </thead>
          <tbody id="subPro">
          </tbody>
         </table>
        </form>
        <div  id="page_div">
		    <div class="M-box3" style="float:right"></div>
		</div>
      </div>
    </div>
    
    <!--添加主栏目-->
    <div class="am-g" id="addPro" style="display:none">
        <form class="am-form">
          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              栏目名称
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
              <input type="text" class="am-input-sm" style="margin:0px;text-align:left" id="scolName">
            </div>
          </div>

          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
              栏目详述
            </div>
            <div class="am-u-sm-12 am-u-md-4 am-u-end col-end">
              <textarea rows="15" id="scolSum"></textarea>
            </div>
          </div>

        </form><br />
        <div class="am-u-sm-4 am-u-md-3 am-text-right">
        <button type="button" class="am-btn am-btn-primary am-btn-xs" id="add">添加</button>
    <button type="button" class="am-btn am-btn-primary am-btn-xs clear"  style="margin-left:2%">取消</button>
        </div>
    </div>
      
       <!--添加主栏目-->
        <!--更新主栏目-->
    <div class="am-g" id="updataPro" style="display:none">
        <form class="am-form">
            <div class="am-g am-margin-top">
            <div class="am-u-sm-8 am-u-md-4 am-text-right" style="margin-left:2%">
              <b>栏目信息</b>
            </div>
          </div>
          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              栏目名称
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
              <input type="text" class="am-input-sm" style="margin:0px;text-align:left"id="sName">
            </div>
          </div>
           <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              主栏目
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
              <select id="s_mcol">
               </select>
            </div>
          </div>
          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
              栏目详述
            </div>
            <div class="am-u-sm-12 am-u-md-4 am-u-end col-end">
              <textarea rows="15" id="sSum"></textarea>
            </div>
          </div>

        </form><br />
        <div class="am-u-sm-4 am-u-md-3 am-text-right">
        <button type="button" class="am-btn am-btn-primary am-btn-xs" id="updata">更新</button>
    <button type="button" class="am-btn am-btn-primary am-btn-xs clear"  style="margin-left:2%">取消</button>
        </div>
    </div><br />
      
       <!--更新主栏目-->
  </div>
  <!-- content end -->

</div>

<a href="#" class="am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}">
  <span class="am-icon-btn am-icon-th-list"></span>
</a>


<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="../../assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="../../assets/js/amazeui.min.js"></script>
<script src="../../js/left-nav.js"></script>
<script src="../../js/header.js"></script>
<script src="../../js/jquery.pagination.js"></script>
<script src="../../js/index.js"></script>
<script src="../../js/global.js"></script>
<script >
    $(document).ready(function(){
        $("#collapse-nav-3").addClass("am-in");
        searchMcol();
        $.ajax({
			type : "GET",
			url : "/partyBuilding/scol/mcol/1/curPage/1/pageSize/10" ,
			contentType : "application/json",
			dataType : "json",
			success : function(data) {
				//alert(JSON.stringify(data));
				if(data.code == "200") {
					var pag = data.pageInfo.totalCount; //信息列表总记录数目
					pagination(pag, 1);
					showPro(data);
					
				}
			},
			error : function() {
				
			}
		});  
        
        scolList();
    })
    
        
    // 添加栏目
    $("#add_btn").on("click",function(){
        $("#proTab").hide();
        $("#addPro").show();
        $("#updataPro").hide();
        
    })
    
    // 取消按钮点击事件
    $(".clear").on("click",function(){
        $("#proTab").show();
        $("#addPro").hide();
        $("#updataPro").hide();
        $("#addBtn").show();
    })
    
    // 详情按钮点击事件
    function detail(node){
        $("#proTab").hide();
        $("#updataPro").show();
        $("#addBtn").hide();
        var pkScol = node.getAttribute("pkScol");
        setCookie("pkScol",pkScol);
        alert(pkScol);
        $.ajax({
        	type : "GET",
        	url : "/partyBuilding/scol/"+pkScol ,
        	contentType : "application/json",
        	dataType : "json",
        	success : function(data) {
        		alert(JSON.stringify(data));
        		
        		if(data.code == "200") {
        			var fkMcol = data.sCol.fkMcol;
        			$("#sName").val(data.sCol.scolName);
        			$("#sSum").val(data.sCol.scolSum);
        			$.ajax({
        				type : "GET",
        				url : "/partyBuilding/mcol" ,
        				contentType : "application/json",
        				dataType : "json",
        				success : function(data) {
        					//alert(JSON.stringify(data));
        					
        					if(data.code == "200") {
        						$.each(data.mCols, function(num, mCols) {
        						$("#s_mcol").append("<option value='"+mCols.pkMcol+"'>"+mCols.mcolName+"</option>")
        					});
        						$("#s_mcol").find("option[value='"+fkMcol+"']").attr("selected","selected");
        					}
        				},
        				error : function() {
        					
        				}
        			});  
        			
        		}
        		
        	},
        	error : function() {
        		
        	}
        });  
    }
    
 // 删除按钮点击事件
    function del(node){
        var pkScol = node.getAttribute("pkScol");
        alert(pkScol);
        $.ajax({
        	type : "DELETE",
        	url : "/partyBuilding/scol/"+pkScol,
        	data :{
        		pkSCol:pkScol,
         	},
        	contentType : "application/json",
        	dataType : "json",
        	success : function(data) {
        		alert(JSON.stringify(data));
        		
        		if(data.code == "200") {
        			alertModal("提示", "删除成功", function() {
					});
        			node.parentNode.parentNode.remove();
        		}
        		
        	},
        	error : function() {
        		alertModal("提示", "存在信息不能删除", function() {
				});
        		
        	}
        });  
    }
    
    var totalPage = 0; //总页数
	function pagination(pag, cur) {

		var page = 1; //页数
		page = parseInt(pag / 10);
		var pageSize = (pag % 10);
		if (pageSize == 0) {
			totalPage = page;
		} else {
			totalPage = page + 1;
		}

		$('.M-box3').pagination({
			pageCount : totalPage,
			current : cur,
			jump : true,
			coping : true,
			homePage : '首页',
			endPage : '末页',
			prevContent : '上页',
			nextContent : '下页'
		});

	}
    
    
      function showPro(data){
    	  $("#subPro").html("");
    	  $.each(data.sCols, function(num, sCols) {
    	        $("#subPro").append('<tr><td>'+sCols.scolName+'</td><td>'+getDate(sCols.addTime)+'</td>'+
    	        '<td><a style="cursor: pointer; color:#0e90d2;margin-right:20px" pkScol="'+sCols.pkScol+'" onclick="detail(this)">详情</a>'+
    	        '<a style="cursor: pointer;color:#BD2D30" pkScol="'+sCols.pkScol+'" onclick="del(this)">删除</a></td></tr>');
    	        });
    };
    
/*     添加按钮事件 */
$("#add").click(
		function() {
			var content = {};

			//主栏目
			var mcol = $("#scolName").val();
			if(mcol==""){
				alertModal("提示", "请填写子栏目");
				return false;
			}
			content["scolName"] = mcol;
			//子栏目
			var addSum = $("#scolSum").val();
			if(addSum==""){
				alertModal("提示", "请填写栏目详述");
				return false;
			}
			content["scolSum"] = addSum;
			var fkMcol=$("#mcol").val();
			content["fkMcol"] = fkMcol;
			add(content);
		});

/* 添加栏目 */
function add(content) {
	$.ajax({
		type : "POST",
		url : "/partyBuilding/scol",
		data : encrypt(content),
		contentType : "application/json",
		dataType : "json",
		success : function(data) {
			ALERT(JSON.stringify(data));
			if (data.code == "200") {
				alertModal("提示", "添加成功", function() {
				window.location.href="/partyBuilding/back/proManage/subPro.html";
				});
			} else {
				alertModal("警告", data.msg);
			}
		},
		error : function() {
			alertModal("警告", "服务器开小差了");
		}
	});
}

/*     更新按钮事件 */
$("#updata").click(
		function() {
			var content = {};

			var pkScol = getCookie("pkScol");
			content["pkScol"] = pkScol;
			//主栏目
			var scol = $("#sName").val();
			if(scol==""){
				alertModal("提示", "请填写主栏目");
				return false;
			}
			content["scolName"] = scol;
			var fkMcol = $("#s_mcol").val();
			content["fkMcol"] = fkMcol;
			//栏目详情
			var sSum = $("#sSum").val();
			if(sSum==""){
				alertModal("提示", "请填写栏目详述");
				return false;
			}
			content["sSum"] = sSum;
			alert(JSON.stringify(content));
			updata(content);
		});

/* 添加栏目 */
function updata(content) {
	$.ajax({
		type : "PUT",
		url : "/partyBuilding/scol",
		data : encrypt(content),
		contentType : "application/json",
		dataType : "json",
		success : function(data) {
			ALERT(JSON.stringify(data));
			if (data.code == "200") {
				alertModal("提示", "添加成功", function() {
				window.location.href="/partyBuilding/back/proManage/subPro.html";
				});
			} else {
				alertModal("警告", data.msg);
			}
		},
		error : function() {
			alertModal("警告", "服务器开小差了");
		}
	});
}
</script>

</body>
</html>
